/*
 * @Description:可视化表单
 * @Author: Zzt
 * @Date: 2022-08-09 14:59:01
 * @LastEditTime: 2022-08-23 20:49:03
 */

import { Form, Button, Input, Upload } from 'antd';
import { useState } from 'react';
import { UploadOutlined } from '@ant-design/icons';
import { saveFolderLevel } from '@/api/accession';
import { uploadPath } from '@/api/upload';
import JPDatePicker from '@/components/JPComponents/JPDatePicker';
import type { UploadChangeParam } from 'antd/lib/upload';
import type { UploadFile } from 'antd/lib/upload/interface';

const PlanRecord = (prop: any) => {
  // 存储上传成功后返回的完整条目数据
  const [latestRecord, setLatestRecord] = useState({});
  console.log(latestRecord);
  const onChange = (info: UploadChangeParam<UploadFile>) => {
    // console.log(info);
    const { file } = info;
    if (file.status === 'done') {
      saveExcel(file, file.response);
    }
  };

  const saveExcel = (file: UploadFile, res: any) => {
    const params: any = { batchId: prop.id };
    params.folderAtt = {
      fileSize: file.size,
      fileUrl: res.data?.url || '',
      status: true
    };
    saveFolderLevel(params).then((res) => {
      console.log('save s', res.data);
      setLatestRecord(res.data);
    });
  };
  // console.log('表格显示', prop);
  return (
    <>
      <Form.Item label="计划标题" name="planTitle">
        <Input />
      </Form.Item>
      <Form.Item label="计划时间">
        <Form.Item name="planStartTime" noStyle>
          <JPDatePicker placeholder="计划开始时间" valueFormat="YYYY-MM-DD 00:00:00" />
        </Form.Item>
        到
        <Form.Item name="planEndTime" noStyle>
          <JPDatePicker placeholder="计划结束时间" valueFormat="YYYY-MM-DD 00:00:00" />
        </Form.Item>
      </Form.Item>
      <Form.Item label="计划内容">
        <Button type="link">查看范文</Button>
        <Form.Item name="planContent">
          <Input.TextArea rows={4} />
        </Form.Item>
      </Form.Item>
      <Form.Item label="添加附件" name="attachment">
        <Upload action={uploadPath} name="file" maxCount={1} onChange={onChange}>
          <Button icon={<UploadOutlined />}>点击上传</Button>
        </Upload>
      </Form.Item>
    </>
  );
};

export default PlanRecord;
